package javafx.com;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.stage.Stage;

/**
 * @Classname main
 * @Date 2021/09/21 10:23
 * @Author by yx
 * @Description :
 */
public class main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        Button button1 = new Button("button1");
        Button button2 = new Button("button2");
        Button button3 = new Button("button3");
        Button button4 = new Button("button4");
        Button button5 = new Button("button5");
        Button button6 = new Button("button6");
        Button button7 = new Button("button7");
        Button button8 = new Button("button8");
        Button button9 = new Button("button9");

        GridPane gridPane = new GridPane();
        gridPane.setStyle("-fx-background-color: #EE6AA7");

        // 设置组件在gidPane上的位置,即第几列第几行-列/行
        gridPane.add(button1, 0, 0);
        gridPane.add(button2, 1, 0);
        gridPane.add(button3, 2, 0);
        gridPane.add(button4, 3, 0);
        gridPane.add(button5, 0, 1);
        gridPane.add(button6, 1, 1);
        gridPane.add(button7, 2, 1);
        gridPane.add(button8, 3, 1);

        // 水平/垂直间距
//        gridPane.setHgap(10);
//        gridPane.setVgap(10);
        // 内边距
//        gridPane.setPadding(new Insets(10));
        // 组件外边距-会自动补位->实现整体布局一致
//        GridPane.setMargin(button1, new Insets(10));
        // 默认显示方式-
//        gridPane.setAlignment(Pos.CENTER);

        // 另一种方式设置组件位置
//        GridPane.setConstraints(button9, 1, 1);

//        GridPane.setRowIndex(button9,0);
//        GridPane.setColumnIndex(button9, 1);

//        gridPane.getChildren().add(button9);

        // 单独为列/行设置间距
        gridPane.getColumnConstraints().add(new ColumnConstraints(100));
        gridPane.getRowConstraints().add(new RowConstraints(100));

        Scene scene = new Scene(gridPane);
        primaryStage.setScene(scene);
        primaryStage.setWidth(800);
        primaryStage.setHeight(800);
        primaryStage.setTitle("javafx");
        primaryStage.show();

    }
}
